package net.lovesrc.allin.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhouzhou.fastjava.http.MyHttpRequest;
import com.zhouzhou.fastjava.http.Requests;
import net.lovesrc.allin.Message;
import net.lovesrc.allin.biz.lbc.BaseLbcService;
import net.lovesrc.allin.biz.lbc.LbcService;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/test")
public class TestController extends BaseController {

    @Autowired
    private LbcService lbcService;

    @GetMapping("/proxy")
    public Message String(String text) {
        HttpClientBuilder httpClientBuilder = Requests.newHttpClientBuilder(new BasicCookieStore());
        httpClientBuilder.setProxy(new HttpHost("47.101.155.59", 18028));
        CloseableHttpClient httpClient = httpClientBuilder.build();
        String s = MyHttpRequest.get(httpClient, "http://pv.sohu.com/cityjson")
                .execute()
                .asText();
        System.out.println(s);
        return Message.success(s);
    }

    @GetMapping("/test")
    public Message test(String text) {
        {
            JSONObject row = queryForRow(jdbcTemplate, "select mobile from t_lbc_account where goldAccount + silverAccount > 30 and cpValue = 0 and mine = 0 limit 1");
            lbcService.updateRepeatBuyJy(row.getString("mobile"), true);
        }

        {
            JSONObject row = queryForRow(jdbcTemplate, "select mobile from t_lbc_account where repeatBuyKj = 1 and cpValue < 0.03 and goldAccount + silverAccount > 10 limit 1");
            lbcService.buyKj4CPValue(row.getString("mobile"), 0.03, BaseLbcService.Proxy.PROXY_MIKE);
        }
        return Message.success();
    }


}
